<?php if(!defined('BASEPATH')) exit('No direct script access allowed!');

class Actors_Model extends MY_Model {
	protected $_table_name = 'actors';

	public function __construct() {
		parent::__construct();
	}	
	
	public function get_by_name($name) {
		$this->db->where('name',$name);
		$rs = $this->db->get($this->_table_name);
		$rs = $rs->result_array();
		return $rs[0];
	}
	
	public function lists_array(){
		$rs = $this->db->get($this->_table_name)->result_array();
		$data = array();
		$data[0] = '';
		foreach($rs as $row){
			$data[ $row['id'] ] = $row['name'];
		}
		return $data;
	}
	/*
	public function get($id='') {
		$user = parent::get($id);
		return $user;
	}

	public function get_name($id) {
		$this->db->where('id',$id);
		$rs = $this->db->get($this->_table_name);
		$rs = $rs->result_array();
		return $rs[0]["nama"];
	}
	
	public function insert(&$input) {
		$data['username'] = $input->post('username');
		$data['nama'] = $input->post('nama');
		$data['password'] = md5($input->post('password'));
		$data['email'] = $input->post('email');
		$this->db->insert($this->_table_name, $data);
		return parent::last_inserted_id();
	}
	
	public function update(&$input, $id) {
		$user = $this->get($id);
		$data['username'] = $user['username'];
		$data['nama'] = $input->post('nama');
		$pass = $input->post('password');
		if($pass!='')
			$data['password'] = md5($pass);
		else
			$data['password'] = $user['password'];
		
		$data['email'] = $input->post('email');
		$this->db->update($this->_table_name, $data, array('id'=>$user['id']));
	}
	
	public function is_valid_to_delete($user_id){
		$ci = &get_instance();
		
		$ci->load->model('prospeklog_model','prospeklog');
		$prospeklog = $ci->prospeklog->get_by_user_id($user_id);
		if(count($prospeklog)>0)
			return false;
				
		return true;
	}
	
	public function delete($id){
		$this->db->delete($this->_table_name, array('id'=>$id));
	}

	public function change_password($user_id, $new_password) {
		$this->db->update($this->_table_name, array('password'=>$this->_encrypt($new_password)), array('id'=>$user_id));
	}

	public function encrypt_password($password) {
		return $this->_encrypt($password);
	}
	*/
}
